package com.cskaoyan.service.user.impl;

import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketCollect;
import com.cskaoyan.bean.po.MarketCollectExample;
import com.cskaoyan.mapper.MarketAddressMapper;
import com.cskaoyan.mapper.MarketCollectMapper;
import com.cskaoyan.service.user.UserCollectService;
import com.cskaoyan.util.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jzp
 * @since 2022/11/19 21:54
 */
@Service
public class UserCollectServiceImpl implements UserCollectService {
    @Autowired
    MarketCollectMapper marketCollectMapper;

    @Override
    public CommonData list(BasePageInfo info, String userId, String valueId) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketCollectExample example = new MarketCollectExample();
        MarketCollectExample.Criteria criteria = example.createCriteria();
        if (!StringUtil.isEmpty(userId)) {
            try {
                criteria.andUserIdEqualTo(Integer.valueOf(userId));
            }catch (Exception e){
                return null;
            }

        }
        if (!StringUtil.isEmpty(valueId)) {
            try {
                criteria.andValueIdEqualTo(Integer.valueOf(valueId));
            }catch (Exception e){
                return null;
            }

        }
        // 排序
        example.setOrderByClause(info.getSort()+" "+info.getOrder());
        List<MarketCollect> marketCollects = marketCollectMapper.selectByExample(example);

        PageInfo<MarketCollect> pageInfo = new PageInfo<>(marketCollects);


        return CommonData.data(pageInfo);
    }
}
